<!--  -->
<template>
  <div id="main">
    <h2>直辖业务管理</h2>
    <div id="search-card">
      <el-form ref="search" :model="search" :inline="true" :rules="rules">

        <el-form-item prop="date">
          <!-- <el-date-picker v-model="search.date" type="date" placeholder="请选择日期" style="width:140px" /> -->
          <el-date-picker
            v-model="search.date"
            value-format="yyyy-MM-dd"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" style="margin-left:10px" @click="submit('search')">提交</el-button>
          <el-button icon="el-icon-refresh" circle @click="refresh()" />
        </el-form-item>
      </el-form>
    </div>
    <!-- <div id="search-card">
      <div id="search-content">
        <el-form v-model="search" :inline="true">

          <el-form-item label="昵称">
            <el-input v-model="search.username" />
          </el-form-item>

          <el-form-item label="所属机构">
            <el-select v-model="search.orgId" placeholder="请选择">
              <el-option
                v-for="o in org"
                :key="o.orgId"
                :value="o.orgId"
                :label="o.orgName"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="用户角色">
            <el-select v-model="search.userGroup" placeholder="请选择">
              <el-option key="1" label="系统管理员" value="1" />
              <el-option key="2" label="代理人" value="2" />
              <el-option key="3" label="机构管理员" value="3" />
              <el-option key="4" label="分支机构管理员" value="4" />
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" style="margin-left:10px" @click="conditionQuery">查找</el-button>
            <el-button icon="el-icon-refresh" circle @click="fetchData()" />
          </el-form-item>

        </el-form>
      </div>

    </div> -->
    <div class="tab">
      <el-tabs v-model="activeName">
        <el-tab-pane label="代理人统计表" name="first">
          <div id="table-area">
            <el-table
              v-loading="listLoading"
              :data="list.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              element-loading-text="Loading"
              border
              fit
              highlight-current-row
            >

              <el-table-column
                label="序号"
                type="index"
                width="80"
                align="center"
              >
                <template scope="scope">
                  <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
                </template>
              </el-table-column>

              <el-table-column
                align="center"
                prop="dailiren.realname"
                label="代理人"
              />

              <el-table-column
                align="center"
                prop="ALLcount"
                label="订单数量"
              />

              <el-table-column
                align="center"
                prop="ALLmoney"
                label="订单金额"
              />

              <el-table-column
                align="center"
                prop="fenqicount"
                label="分期订单数量"
              />

              <el-table-column
                align="center"
                prop="fenqiprice"
                label="分期订单金额"
              />

              <el-table-column
                align="center"
                prop="wxcount"
                label="微信订单数量"
              />

              <el-table-column
                align="center"
                prop="wxprice"
                label="微信订单金额"
              />

              <el-table-column
                align="center"
                prop="kuaiJiecount"
                label="快捷订单数量"
              />

              <el-table-column
                align="center"
                prop="kuaiJieprice"
                label="快捷订单金额"
              />

            </el-table>

            <div id="pages">
              <el-pagination
                :current-page="currentPage"
                :page-sizes="[5,10]"
                :page-size="pagesize"
                layout="total, sizes,prev, pager, next"
                :total="list.length"
                prev-text="上一页"
                next-text="下一页"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </el-tab-pane>
        <el-tab-pane label="机构统计表" name="second">
          <div id="table-area">
            <el-table
              v-loading="listLoading2"
              :data="list2.slice((currentPage-1)*pagesize,currentPage*pagesize)"
              element-loading-text="Loading"
              border
              fit
              highlight-current-row
            >

              <el-table-column
                label="序号"
                type="index"
                width="80"
                align="center"
              >
                <template scope="scope">
                  <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
                </template>
              </el-table-column>

              <el-table-column
                align="center"
                prop="RealName"
                label="代理人"
              />

              <el-table-column
                align="center"
                prop="OrgName"
                label="品牌名称"
              />

              <el-table-column
                align="center"
                prop="CampusName"
                label="机构名称"
              />

              <el-table-column
                align="center"
                prop="ALLcount"
                label="订单数量"
              />

              <el-table-column
                align="center"
                prop="ALLmoney"
                label="订单金额"
              />

              <el-table-column
                align="center"
                prop="fenqicount"
                label="分期订单数量"
              />

              <el-table-column
                align="center"
                prop="fenqiprice"
                label="分期订单金额"
              />

              <el-table-column
                align="center"
                prop="wxcount"
                label="微信订单数量"
              />

              <el-table-column
                align="center"
                prop="wxprice"
                label="微信订单金额"
              />

              <el-table-column
                align="center"
                prop="kuaiJiecount"
                label="快捷订单数量"
              />

              <el-table-column
                align="center"
                prop="kuaiJieprice"
                label="快捷订单金额"
              />
            </el-table>

            <div id="pages">
              <el-pagination
                :current-page="currentPage"
                :page-sizes="[5,10]"
                :page-size="pagesize"
                layout="total, sizes,prev, pager, next"
                :total="list.length"
                prev-text="上一页"
                next-text="下一页"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';
import { countZhixiaBusiness, countZhixiaBusiness2 } from '@/api/statistic'
export default {
// import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    return {
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      list: [],
      listLoading: false,
      list2: [],
      listLoading2: false,
      activeName: 'first',
      search: {
        date: ''
      },
      rules: {
        date: [
          { required: true, message: '请选择日期', trigger: 'blur' }
        ]
      }
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.fetchData()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    // 每页下拉显示数据
    handleSizeChange: function(size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function(currentPage) {
      this.currentPage = currentPage
    },
    handleClick(row) {
      console.log(row)
    },
    fetchData() {
      this.listLoading = true
      this.listLoading2 = true
      const nowDate = new Date()
      const date = {
        year: nowDate.getFullYear(),
        month: nowDate.getMonth() < 9 ? '0' + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1,
        date: nowDate.getDate() <= 9 ? '0' + nowDate.getDate() : nowDate.getDate()
      }
      const systemDate = date.year + '-' + date.month + '-' + date.date
      console.log(systemDate)
      countZhixiaBusiness(systemDate, systemDate).then((resp) => {
        if (resp.obj != null) {
          this.list = resp.obj
        }
        this.listLoading = false
        countZhixiaBusiness2(systemDate, systemDate).then((res) => {
          if (res.obj != null) {
            this.list2 = res.obj
          }
          this.listLoading2 = false
        })
      })
    },
    submit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.listLoading = true
          this.listLoading2 = true
          this.date1 = this.search.date[0]
          this.date2 = this.search.date[1]
          console.log(this.date1)
          console.log(this.date2)
          countZhixiaBusiness(this.date1, this.date2).then((resp) => {
            this.list = resp.obj
            this.listLoading = false
            countZhixiaBusiness2(this.date1, this.date2).then((res) => {
              this.list2 = res.obj
              this.listLoading2 = false
            })
          })
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },
    refresh() {
      this.search.date = []
      this.fetchData()
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped>
#main{
  margin-left: 5px;
  margin-right: 5px;
}
#table-area{
  margin-left: 10px;
  margin-right: 10px;
}
#search-card {
  line-height: 0px;
  margin-left: 10px;
  text-align: left;
  width: 100%;
  height: 70px;
  overflow-x: hidden;
}
</style>
